package edu.ChildrensBooks.model

class Book {

	String title;
	String author;
	String description;
	String isbn;
	int minGradeLevel;
	int maxGradeLevel;
	String language;
	String category;

	Book(String title, String author, String description, String isbn, int minGradeLevel, int maxGradeLevel, String language, String category) {
		this.title = title
		this.author = author
		this.description = description
		this.isbn = isbn
		this.minGradeLevel = minGradeLevel
		this.maxGradeLevel = maxGradeLevel
		this.language = language
		this.category = category
	}

	static constraints = {
		title(blank: false)
		author(blank: false)
		description(nullable: true)
		isbn(nullable: true, matches: '(97[89][- ]){0,1}[0-9]{1,5}[- ][0-9]{1,7}[- ][0-9]{1,6}[- ][0-9X]')
		minGradeLevel(range:0..6, validator: { minGradeLevel, book ->
			return minGradeLevel <= book.getMaxGradeLevel()})
		maxGradeLevel(range:0..6, validator: { maxGradeLevel, book ->
			return maxGradeLevel >= book.getMinGradeLevel()})
		language(nullable: true)
		category(inList:["General Leisure Reading", "Reading skills", "Math skills", "Health", "Science"])
	}
}
